﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;

/// <summary>
/// Description résumée de CreneauService
/// </summary>
/// 
namespace BLL
{
    public class CreneauService
    {
        private ICreneauManager creneauManager;

        public CreneauService(ICreneauManager creneauManager)
        {
            this.creneauManager = creneauManager;
        }

        public CRENEAU createCreneau(int programmeId, int ordre, int activiteId, int siteId)
        {
            CRENEAU creneau = new CRENEAU();
            creneau.PROGRAMMEID = programmeId;
            creneau.ORDRE = ordre;

            if (activiteId == -1)
                creneau.ACTIVITEID = null;
            else
                creneau.ACTIVITEID = activiteId;

            creneau.SITEID = siteId;

            try
            {
                this.creneauManager.addCreneau(creneau);
                return creneau;
            }

            catch (Exception ex)
            {
                return null;
            }

        }

        public bool deleteCreneau(int creneauId)
        {
            return creneauManager.deleteCreneau(creneauId);
        }


        public bool updateCreneau(int id, int programmeId, int ordre, int activiteId, int siteId)
        {
            try
            {
                CRENEAU creneau = creneauManager.getCreneauById(id);
                creneau.PROGRAMMEID = programmeId;
                creneau.ORDRE = ordre;

                if (activiteId == -1)
                    creneau.ACTIVITEID = null;
                else
                    creneau.ACTIVITEID = activiteId;
                creneau.SITEID = siteId;

                creneauManager.updateCreneau();

                return true;
            }

            catch (Exception ex)
            {
                return false;
            }
        }

        public CRENEAU getCreneauById(int id)
        {
            return creneauManager.getCreneauById(id);
        }

        public List<CRENEAU> getAllCreneaux()
        {
            return this.creneauManager.getAllCreneaux();
        }

        public CRENEAU getCreneauForProgrammeAndOrder(int programmeId, int ordre)
        {
            return creneauManager.getCreneauForProgrammeAndOrder(programmeId, ordre);
        }

        public List<CRENEAU> getCreneauxAtDateAndOrder(DateTime date, int ordre)
        {
            return creneauManager.getCreneauxAtDateAndOrder(date, ordre);
        }

        public List<CRENEAU> getCreneauxAtDate(DateTime date)
        {
            return creneauManager.getCreneauxAtDate(date);
        }

    }
}